package com.lvmama.pangolin.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lvmama.pangolin.common.DateUtil;
import com.lvmama.pangolin.entity.LineDataVO;
import com.lvmama.pangolin.entity.ProductGrade;
import com.lvmama.pangolin.service.ProductGradeService;

import net.sf.json.JSONArray;

@Controller
public class ProductGradeController {
	@Autowired
	private ProductGradeService prodGrade;
	
	@RequestMapping("/getProductGrade")
	@ResponseBody
	public Map<String, Object> getStatList(){
		Map<String, Object> result = getResult();
		List<LineDataVO> prodGrades = new ArrayList<>();
		List<ProductGrade> prodScoreList=prodGrade.findAll();
		for(ProductGrade score:prodScoreList){
			LineDataVO product_grade = getLineDataVO();
			product_grade.setTime(DateUtil.ymdSDF.format(score.getCreateDate()));
			product_grade.setCategory(score.getCompanyCode().replace("_C_CODE", ""));
			product_grade.setAmount(Double.valueOf(score.getProductGrade()));
			prodGrades.add(product_grade);
		}
		JSONArray prodGradeData = JSONArray.fromObject(prodGrades);
		result.put("prodGradeData",prodGradeData );
		return result;
	}
	public Map<String, Object> getResult() {
        Map<String, Object> result = new HashMap<String, Object>();
        return result;
    }
	public LineDataVO getLineDataVO(){
		
		return new LineDataVO();
	}
}
